﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_Order
/// </summary>
public class DAL_Order
{
    DbProvider db = new DbProvider();

    public void Order_Insert(DTO_Order obj)
    {

        string sql = string.Format("INSERT INTO [Order] VALUES ('{0}','{1}','{2}','{3}','{4}',N'{5}',N'{6}','{7}',N'{8}','{9}','{10}')",obj.ID, obj.Cus_Id, obj.TotalMoney, obj.PayMethod, obj.Date, obj.Cus_Name, obj.Cus_Add, obj.Cus_Province, obj.Cus_Phone, obj.Check,obj.Finish);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void Order_UpdateByAll(string Id, DTO_Order obj)
    {

        string sql = string.Format("UPDATE [Order] SET [Cus_Id] = '{0}',TotalMoney = '{1}',[PayMethod] = '{2}',[Date] = '{3}',[Cus_Name] = {4}',[Cus_Add] = '{5}',[Cus_Povince] = {6}',[Cus_Phone] = '{7}',[Check] = '{8}', Finish = '{9}' WHERE [Id] = '{10}'", obj.Cus_Id, obj.TotalMoney, obj.PayMethod, obj.Date, obj.Cus_Name, obj.Cus_Add, obj.Cus_Province, obj.Cus_Phone, obj.Check,obj.Finish,Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public void Order_UpdateBySet(string Id, string Set)
    {

        string sql = string.Format("UPDATE [Order] SET {0} WHERE [Id] = '{1}'", Set, Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }
    public void Order_Delete(string Id)
    {

        string sql = string.Format("DELETE FROM [Order] WHERE Id = '{0}'", Id);

        try
        {
            db.ExecuteNonQuery(sql);
        }
        catch (Exception)
        {

            throw;
        }

    }

    public DataTable Order_GetByAll(int Status)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from [Order] where [Status]= '{0}' ", Status);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable Order_GetByTop(int top, string where, string order)
    {
        DataTable dt = new DataTable();
        //string sql = string.Format("select top {0} * from Product where = '{1}' Order by [{2}] DESC,[Order]", top, where,order);
        string sql = "";
        if (top <= 0)
        {
            sql += "SELECT * FROM [Order]";
        }
        else
        {
            sql += "SELECT TOP " + top + " * FROM [Order]";
        }
        if (where != "")
        {
            sql += " WHERE " + where;
        }
        if (order != "")
        {
            sql += " Order by " + order;
        }
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
    public DataTable Order_GetByID(string id)
    {
        DataTable dt = new DataTable();
        string sql = string.Format("select * from [Order] where Id = {0}", id);
        try
        {
            dt = db.ExecuteQuery(sql);

        }
        catch (Exception)
        {

            throw;
        }
        return dt;
    }
}